<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
</head>

<body>
    <h1>登录界面</h1>
    <ul>
        <li>
            用户名<input type="text" id="user">
        </li>
        <li>
            密码<input type="password" id="psw">
        </li>
        <li>
            <button id="login">登录</button>
        </li>
    </ul>
    <script>
        let user = document.querySelector('#user');
        let psw = document.querySelector('#psw');
        let login = document.querySelector('#login');
        login.onclick = function () {
            fetch('/check', {
                method: 'post',
                headers: {
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({ user: user.value, password: psw.value })
            }).then(res => res.json())
                .then(res => {
                    if (res.code === 10000) {
                        location.replace('/index');
                    }else{
                        alert(res.msg);
                        location.reload();
                    }
                })
        }
    </script>
</body>

</html>